package ch.simplix.android.babel.explicit;

import java.util.Locale;

import android.app.Activity;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.os.Bundle;
import android.os.IBinder;
import ch.simplix.android.speech.SpeechService;
import ch.simplix.android.speech.string.FrenchString;
import ch.simplix.android.speech.string.GermanString;
import ch.simplix.android.speech.string.ItalianString;
import ch.simplix.android.speech.string.LocalizedString;
import ch.simplix.android.speech.string.SpanishString;
import ch.simplix.android.speech.string.UKString;
import ch.simplix.android.speech.string.USString;

public class ExplicitBabel extends Activity {
    
    	private SpeechService speechService;

    	/** Called when the activity is first created. */
    	@Override
    	public void onCreate(Bundle savedInstanceState) {
    		super.onCreate(savedInstanceState);
    		setContentView(R.layout.main);
    		
    		bindService(new Intent(this, SpeechService.class), babelConnection,
    				Context.BIND_AUTO_CREATE);
    	}

    	@Override
    	protected void onDestroy() {    		
    		unbindService(babelConnection);
    		super.onDestroy();
    	}

    	/**
    	 * {@link ServiceConnection} for the {@link SpeechService}
    	 */
    	private ServiceConnection babelConnection = new ServiceConnection() {

    		@Override
    		public void onServiceConnected(ComponentName className, IBinder service) {			
    			speechService = ((SpeechService.LocalBinder) service).getService();
    			speechService.addPhrase(new LocalizedString(Locale.US,
    					"This is an explicit service request."));			
    			speechService.addPhrase(new LocalizedString(Locale.UK,
    					"This is an explicit service request."));
    			speechService.addPhrase(new LocalizedString(Locale.GERMAN,
    					"Dies ist ein expliziter Aufruf eines Service."));
    			speechService.addPhrase(new LocalizedString(Locale.FRENCH,
    					"C'est un appel explicite au service"));
    			speechService.addPhrase(new LocalizedString(Locale.ITALIAN,
    					"Questo è un esplicito richiamo al servizio."));
    			speechService.addPhrase(new LocalizedString(new Locale("spa", "ESP"),
    					"Esta es una llamada explícita al servicio."));

    		}

    		@Override
    		public void onServiceDisconnected(ComponentName name) {
    			speechService = null;
    		}

    	};
    }